<template>
  <div class="app-container" v-loading="loading">
    <el-input v-model="filterText" prefix-icon="el-icon-search"
              placeholder="请输入关键词" style="margin-bottom:30px;"/>
    <!--ref 为名称
       data 数据
       props
    -->
    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />
  </div>
</template>


<script>
  import { getSubjectList } from '@/api/edu/subject'

  export default {

    data() {
      return {
        loading: true,
        filterText: '',
        data2: [],
        defaultProps: {
          children: 'children',
          label: 'title'
        }
      }
    },
    watch: {
      filterText(val) {
        this.$refs.tree2.filter(val)
      }
    },
    created() {
      getSubjectList().then(response => {
        this.loading = false
        this.data2 = response.data.data2

      })
    },
    //检索节点
    methods: {
      filterNode(value, data) {
        // console.log(data.title.toLowerCase());
        if (!value) return true
        //全部转换为大写进行比较
        return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1
      }
    }
  }
</script>


<style scoped>

</style>
